package pub.tbc.toolkit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Closeable;
import java.io.IOException;

/**
 * @author tbc
 * @version 1.0 {2016年3月25日 下午12:52:13}
 */
@Deprecated
public final class CloseUtil {
    private static Logger log = LoggerFactory.getLogger(CloseUtil.class);

    private CloseUtil() {
        throw new AssertionError("No " + getClass().getCanonicalName() + " instances for you!");
    }

    public static void close(Closeable c) {
        if (c != null) {
            try {
                c.close();
            } catch (IOException e) {
                log.error("clse to Closeable failure : ", e);
            }
        }
    }

    public static void close(AutoCloseable c) {
        if (c != null) {
            try {
                c.close();
            } catch (Exception e) {
                log.error("close to AutoCloseable failure : ", e);
            }
        }
    }

    public static void closeAll(Closeable... cs) {
        // before jdk8 ,性能应该更好一些，猜的
        for (Closeable c : cs) {
            close(c);
        }
    }

    public static void closeAll(AutoCloseable... cs) {
        for (AutoCloseable c : cs) {
            close(c);
        }
    }

}